const app = getApp()
const request = require('../../utils/https.js')

Page({

  /**
   * 页面的初始数据
   */
  data: {
    getMoney: 0,
    reallyMoney: 0,
    value: 0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    const that = this;
  },
  chenge(e) {
    console.log(e.detail.value)
    const that = this;

    let reallyMoney = 0;
    if (e.detail.value < 800) {
      reallyMoney = 0
    } else if (e.detail.value >= 800 && e.detail.value < 4000) {
      reallyMoney = (e.detail.value - 800) * 0.2
    } else if (e.detail.value >= 4000 && e.detail.value < 20000) {
      reallyMoney = e.detail.value * 0.16
    }

    that.setData({
      getMoney: Number(e.detail.value).toFixed(2), //提现多少钱
      reallyMoney: Number(reallyMoney).toFixed(2), //扣款多少钱
      actualMoney: Number(e.detail.value - reallyMoney).toFixed(2) //实际到账
    })
  },
  goiDentity() {
    wx.redirectTo({
      url: '/pages/identity_new/identity_new',
    })
  },
  //提现
  getMoney() {
    const that = this;
    let userId = wx.getStorageSync('userId');
    if (that.data.getMoney != 0 && that.data.getMoney != ' ' && that.data.getMoney >= 0 && that.data.getMoney < 200000 && that.data.getMoney <= that.data.money) {
      //提现
      request._get(getApp().Api_url + 'profit/cash', {
        userId: userId,
        money: that.data.getMoney,
      }, function (res) {
        if (res.data.errCode == 200) {
          console.log('提现成功==>', res.data)
          wx.navigateTo({
            url: '/pages/withdrawal_1/withdrawal_1?getMoney=' + that.data.getMoney + '&actualMoney=' + that.data.actualMoney + '&cashId=' + res.data.data
          })
        } else {
          wx.showToast({
            icon: 'none',
            title: res.data.msg,
          })
        }
      }, function () {})
    } else {
      wx.showToast({
        icon: 'none',
        title: '不符合提现规则',
      })
    }
  },
  //全部提现
  getMoney1() {
    const that = this;
    let userId = wx.getStorageSync('userId');

    console.log('that.data.getMoney===>', that.data.getMoney)
    console.log('that.data.money===>', that.data.money)

    if (that.data.money != 0 && that.data.money != ' ' && that.data.money >= 100 && that.data.money < 20000) {
      //全部提现
      var reallyMoney = 0;
      if (that.data.money < 800) {
        reallyMoney = 0
      } else if (that.data.money >= 800 && that.data.money < 4000) {
        reallyMoney = (that.data.money - 800) * 0.2
      } else if (that.data.money >= 4000 && that.data.money < 20000) {
        reallyMoney = that.data.money * 0.16
      }


      var getMoney = Number(that.data.money).toFixed(2); //提现多少钱
      var reallyMoney = Number(reallyMoney).toFixed(2); //扣款多少钱
      var actualMoney = Number(that.data.money - reallyMoney).toFixed(2); //实际到账


      request._get(getApp().Api_url + 'profit/cash', {
        userId: userId,
        money: that.data.money,
      }, function (res) {
        if (res.data.errCode == 200) {
          console.log('提现成功==>', res.data)
          wx.navigateTo({
            url: '/pages/withdrawal_1/withdrawal_1?getMoney=' + getMoney + '&actualMoney=' + actualMoney + '&cashId=' + res.data.data
          })
        } else {
          wx.showToast({
            icon: 'none',
            title: res.data.msg,
          })
        }
      }, function () {})
    } else {
      wx.showToast({
        icon: 'none',
        title: '不符合提现规则',
      })
    }
  },
  getMoney2() {
    const that = this;


    if (that.data.money != 0 && that.data.money != ' ' && that.data.money >= 100 && that.data.money < 20000) {
      //全部提现
      let reallyMoney = 0;
      if (that.data.money < 800) {
        reallyMoney = 0
      } else if (that.data.money >= 800 && that.data.money < 4000) {
        reallyMoney = (that.data.money - 800) * 0.2
      } else if (that.data.money >= 4000 && that.data.money < 20000) {
        reallyMoney = that.data.money * 0.16
      }

      that.setData({
        value: Number(that.data.money).toFixed(2),
        getMoney: Number(that.data.money).toFixed(2), //提现多少钱
        reallyMoney: Number(reallyMoney).toFixed(2), //扣款多少钱
        actualMoney: Number(that.data.money - reallyMoney).toFixed(2) //实际到账
      })

    } else {
      wx.showToast({
        icon: 'none',
        title: '不符合提现规则',
      })
    }


  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    const that = this;
    let userId = wx.getStorageSync('userId');
    request._get(getApp().Api_url + 'user/hasCert', {
      userId: userId
    }, function (res) {
      if (res.data.errCode == 200) {
        console.log('显示信息==>', res.data)
        that.setData({
          name: res.data.data.username,
          idCard: res.data.data.idCard,
          bankCard: res.data.data.bankCard,
          money: res.data.data.money //可提现金
        })

      }
    }, function () {})
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  }
})